﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace AcesHigh
{
    class Deck
    {
        private int cardIndex;
        private List<Card> cards;
        private static Random rng = new Random();
        private String imagePath;
       /*
        public Deck(String imagePath)
        {
            this.imagePath = imagePath;
            initCards();
            cardIndex = 0;
        }*/

        public Deck()
        {
            //this.imagePath = imagePath;
            initCards();
            cardIndex = 0;
        }

        public bool IsEmpty
        {
            get{ return this.cardIndex == cards.Count; }
        }

        private void initCards() 
        {
            List<Card> list = new List<Card>();
            Suit suit = Suit.Clubs;
            Rank rank;

            for (int i = 0; i < 4; i++)
            {
                rank = Rank.Two;
                for (int j = 2; j < 15; j++)
                {
                    list.Add(new Card(rank, suit, String.Format("{0}\\{1}{2}.png", imagePath, rank, suit)));
                    rank++;
                }
                suit++;
            }
            this.cards = ShuffleCards(list);
        }

        List<Card> ShuffleCards(List<Card> list)
        {
            for (int i=list.Count-1; i > 0; i--)
            {
                int swapIndex = rng.Next(i+1);
                if (swapIndex != i)
                {
                    Card tmp = list[swapIndex];
                    list[swapIndex] = list[i];
                    list[i]= tmp;
                }
            }
            return list;
        }

        /*
         * 
         */
        public Card dealCard()
        {
            if (cardIndex < cards.Count)
            {
                Card c = cards[cardIndex];
                cardIndex++;
                return c;
            }
            return null;
        }
    }
}
